<?php

class browsing extends a_front_controller {
    protected $srv;
    public function __construct($post_handling_enabled=FALSE) {        
        parent::__construct($post_handling_enabled);
        $this->run_auto_view = FALSE;
        $this->srv = new service_l_category();
    }

    public function category($cat_id,$offset=0){
        $uri_parts = $this->uri->segment_array();
       // var_dump($uri_parts);
        
        $processor  = new search_processor_l_search("PRODUCTS");

        //param for filtering product by visibility and deletion status
        $param = new dynamic_param_l_search(microtime(), module_u_search::SEARCH_TYPE_PARAM );
        $param->set_where_line("(products.publish = 1 AND products.is_deleted = 0)");
        $param->set_select_line("DISTINCT(part_num),products.*");        
        $processor->add_param($param);

        //diaply product for a specific cat
        quick_include("search","join_product_category" );
        $processor->add_param(new join_product_category((object)array("id"=>  microtime(), 'type'=> module_u_search::SORT_TYPE_PARAM,'option'=>$cat_id)));
        
        //get stored params from url..
        $caught_params = $processor->add_params_from_url();
        $url_tail = regenerate_url_for_paging($caught_params);

        $count = $processor->count_result();
        $page_link = get_pagigination("category/browsing/category/$cat_id", $count,  module_u_search::DEFAULT_PER_PAGE,$url_tail,5);
        $products = $processor->get_result (new product_m_product(), $offset, module_u_search::DEFAULT_PER_PAGE);

        
        $this->assign("cat_products",$products );
        $this->assign("cat_path",$this->srv->get_cat_path($cat_id));
        $this->assign("selected_params",$caught_params);
        $this->assign("page_link",$page_link);
        $this->assign("count",$count);
        $this->view("category");

    }
    
    public function batch_assign(){
        
    }

    public function index() {
    }
 }
?>